package com.esun.rabbit2.viewer.mainact.optionact;

import android.content.Context;
import android.content.SharedPreferences;

import com.esun.config.Config;
import com.esun.config.Key;

/**
 * @ClassName: ValuesManager
 * @Description: 对preference中push功能的数据进行读写操作
 * @author: Billy Qigs@500wan.com
 * @date: Jul 20, 2012 2:34:58 PM
 * 
 */
public class ValuesManager {
	/** 推送总开关 */
	private boolean state_masterPushSwitch = true;

	/** 设置时间hours */
	private String remindTime_hours;

	/** 设置时间min */
	private String remindTime_mins;

	/** 时间推送开关 */
	private boolean state_timePushSwitch = true;

	/** 双色球开奖推送开关状态 */
	private boolean state_SSQ_lotteryPushSwitch = true;

	/** 大乐透开奖推送开关状态 */
	private boolean state_DLT_lotteryPushSwitch = true;

	/** 足球胜负/任选9场 开奖推送开关状态 */
	private boolean state_RXJ_lotteryPushSwitch = true;

	/** 福彩3D开奖推送开关状态 */
	private boolean state_FC3D_lotteryPushSwitch = true;

	/** 双色球 购买提醒推送开关状态 */
	private boolean state_SSQ_timePushSwitch = true;

	/** 大乐透 购买提醒推送开关状态 */
	private boolean state_DLT_timePushSwitch = true;

	/** 足球胜负/任选9场 购买提醒推送开关状态 */
	private boolean state_RXJ_timePushSwitch = true;

	/** 福彩3D 购买提醒推送开关状态 */
	private boolean state_FC3D_timePushSwitch = true;

	/** 保存信息的sharepreferences */
	private SharedPreferences sharedPrefValues;

	private static ValuesManager valuesManager;

	private static Context context;

	public static ValuesManager getInstance(Context con) {

		if (valuesManager == null) {
			valuesManager = new ValuesManager(con);
		}
		context = con;
		return valuesManager;

	}

	public ValuesManager(Context context) {

		this.sharedPrefValues = context.getSharedPreferences(Config.CLIENT_PREFERENCES, Context.MODE_PRIVATE);
		
	}

	/** 读取推送状态 */
	public void readValue() {

		state_masterPushSwitch = sharedPrefValues.getBoolean(Key.KEY_PARENT_CHECKBOX_PREFERENCE, true);

		state_timePushSwitch = sharedPrefValues.getBoolean(Key.KEY_PARENTTIME_CHECKBOX_PREFERENCE, true);

		state_SSQ_lotteryPushSwitch = sharedPrefValues.getBoolean(Key.KEY_SSQ_PREF, false);
		state_DLT_lotteryPushSwitch = sharedPrefValues.getBoolean(Key.KEY_DLT_PREF, false);
		state_RXJ_lotteryPushSwitch = sharedPrefValues.getBoolean(Key.KEY_ZQRX9_PREF, false);
		state_FC3D_lotteryPushSwitch = sharedPrefValues.getBoolean(Key.KEY_FC3D_PREF, false);

		state_SSQ_timePushSwitch = sharedPrefValues.getBoolean(Key.KEY_SSQTIME_PREF, false);
		state_DLT_timePushSwitch = sharedPrefValues.getBoolean(Key.KEY_DLTTIME_PREF, false);
		state_RXJ_timePushSwitch = sharedPrefValues.getBoolean(Key.KEY_ZQRX9TIME_PREF, false);
		state_FC3D_timePushSwitch = sharedPrefValues.getBoolean(Key.KEY_FC3DTIME_PREF, false);

		remindTime_hours = sharedPrefValues.getString(Key.KEY_SET_TIME_HOURS, Config.NUM00);
		remindTime_mins = sharedPrefValues.getString(Key.KEY_SET_TIME_MINS, Config.NUM00);

	}

	/** 保存开奖信息推送状态，不包含总开关状态 */
	public void saveLotteryPushState() {

		saveOneValue(Key.KEY_SSQ_PREF, state_SSQ_lotteryPushSwitch);
		saveOneValue(Key.KEY_DLT_PREF, state_DLT_lotteryPushSwitch);
		saveOneValue(Key.KEY_ZQRX9_PREF, state_RXJ_lotteryPushSwitch);
		saveOneValue(Key.KEY_FC3D_PREF, state_FC3D_lotteryPushSwitch);

	}

	/** 保存购买提醒推送状态，包含购彩提醒开关状态 */
	public void saveTimePushState() {

		saveOneValue(Key.KEY_PARENTTIME_CHECKBOX_PREFERENCE, state_timePushSwitch);

		saveOneValue(Key.KEY_SSQTIME_PREF, state_SSQ_timePushSwitch);
		saveOneValue(Key.KEY_DLTTIME_PREF, state_DLT_timePushSwitch);
		saveOneValue(Key.KEY_ZQRX9TIME_PREF, state_RXJ_timePushSwitch);
		saveOneValue(Key.KEY_FC3DTIME_PREF, state_FC3D_timePushSwitch);

	}

	/** 保存推送总开关状态 */
	public void saveMasterSwitchState() {

		saveOneValue(Key.KEY_PARENT_CHECKBOX_PREFERENCE, state_masterPushSwitch);

	}

	/** 保存购彩提醒时间 */
	public void saveTimePushNum() {

		saveOneValue(Key.KEY_SET_TIME_HOURS, remindTime_hours);
		saveOneValue(Key.KEY_SET_TIME_MINS, remindTime_mins);

	}

	/** 保存一个键值对 */
	private void saveOneValue(String key, String value) {

		sharedPrefValues = context.getSharedPreferences(Config.CLIENT_PREFERENCES, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = sharedPrefValues.edit();
		editor.putString(key, value);
		editor.commit();

	}

	/** 保存一个键值对 */
	private void saveOneValue(String key, boolean value) {

		sharedPrefValues = context.getSharedPreferences(Config.CLIENT_PREFERENCES, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = sharedPrefValues.edit();
		editor.putBoolean(key, value);
		editor.commit();

	}

	public SharedPreferences getSharedPrefValues() {
		return sharedPrefValues;
	}

	public void setSharedPrefValues(SharedPreferences sharedPrefValues) {
		this.sharedPrefValues = sharedPrefValues;
	}

	public boolean isState_masterPushSwitch() {
		return state_masterPushSwitch;
	}

	public void setState_masterPushSwitch(boolean state_masterPushSwitch) {
		this.state_masterPushSwitch = state_masterPushSwitch;
	}

	public String getRemindTime_hours() {
		return remindTime_hours;
	}

	public void setRemindTime_hours(String remindTime_hours) {
		this.remindTime_hours = remindTime_hours;
	}

	public String getRemindTime_mins() {
		return remindTime_mins;
	}

	public void setRemindTime_mins(String remindTime_mins) {
		this.remindTime_mins = remindTime_mins;
	}

	public boolean isState_timePushSwitch() {
		return state_timePushSwitch;
	}

	public void setState_timePushSwitch(boolean state_timePushSwitch) {
		this.state_timePushSwitch = state_timePushSwitch;
	}

	public boolean isState_SSQ_lotteryPushSwitch() {
		return state_SSQ_lotteryPushSwitch;
	}

	public void setState_SSQ_lotteryPushSwitch(boolean state_SSQ_lotteryPushSwitch) {
		this.state_SSQ_lotteryPushSwitch = state_SSQ_lotteryPushSwitch;
	}

	public boolean isState_DLT_lotteryPushSwitch() {
		return state_DLT_lotteryPushSwitch;
	}

	public void setState_DLT_lotteryPushSwitch(boolean state_DLT_lotteryPushSwitch) {
		this.state_DLT_lotteryPushSwitch = state_DLT_lotteryPushSwitch;
	}

	public boolean isState_RXJ_lotteryPushSwitch() {
		return state_RXJ_lotteryPushSwitch;
	}

	public void setState_RXJ_lotteryPushSwitch(boolean state_RXJ_lotteryPushSwitch) {
		this.state_RXJ_lotteryPushSwitch = state_RXJ_lotteryPushSwitch;
	}

	public boolean isState_FC3D_lotteryPushSwitch() {
		return state_FC3D_lotteryPushSwitch;
	}

	public void setState_FC3D_lotteryPushSwitch(boolean state_FC3D_lotteryPushSwitch) {
		this.state_FC3D_lotteryPushSwitch = state_FC3D_lotteryPushSwitch;
	}

	public boolean isState_SSQ_timePushSwitch() {
		return state_SSQ_timePushSwitch;
	}

	public void setState_SSQ_timePushSwitch(boolean state_SSQ_timePushSwitch) {
		this.state_SSQ_timePushSwitch = state_SSQ_timePushSwitch;
	}

	public boolean isState_DLT_timePushSwitch() {
		return state_DLT_timePushSwitch;
	}

	public void setState_DLT_timePushSwitch(boolean state_DLT_timePushSwitch) {
		this.state_DLT_timePushSwitch = state_DLT_timePushSwitch;
	}

	public boolean isState_RXJ_timePushSwitch() {
		return state_RXJ_timePushSwitch;
	}

	public void setState_RXJ_timePushSwitch(boolean state_RXJ_timePushSwitch) {
		this.state_RXJ_timePushSwitch = state_RXJ_timePushSwitch;
	}

	public boolean isState_FC3D_timePushSwitch() {
		return state_FC3D_timePushSwitch;
	}

	public void setState_FC3D_timePushSwitch(boolean state_FC3D_timePushSwitch) {
		this.state_FC3D_timePushSwitch = state_FC3D_timePushSwitch;
	}

}
